<link rel="stylesheet" href="/static/cloud/css/cloud.css" />
<style type="text/css">
	.content{margin:20px;}
	.content ul{padding-top: 10px;padding-bottom: 10px}
	.content .layui-nav .url{padding-right: 0.5rem;padding-left: 0.5rem;cursor: pointer;text-align: center;line-height: 40px}
	.content .bar{margin-bottom: 0.5rem}
	.content .layui-nav{background: white;color: #6d6d6d;padding: 0}
	.content .table_file_name{color: #00986f;}
	.content .table_file_name:hover{cursor: pointer;color: #5fb878;}
	.content .forbid{color: #cacaca}
</style>
<div class="content">
	<div class="layui-col-md2">
		<div id="admin_menu"></div>
	</div>
	<div class="layui-col-md10" style="background-color: white;padding: 20px;">
		<blockquote class="layui-elem-quote">离线下载服务是基于<a href="http://aria2.github.io/" target="_blank" style="color: blue;">Aria2(点击进入官网下载)</a>运行使用。<a href="http://aria2.github.io/" target="_blank" style="color: blue;">点此Aria2使用和配置教程</a></blockquote>
		<div class="layui-form layui-form-pane" lay-filter="aria2_config">
			
			<input type="text" name="id" class="layui-input layui-hide">
		
			<div class="layui-form-item">
				<label class="layui-form-label">链接地址</label>
				<div class="layui-input-block">
					<input type="text" name="aria2_url" autocomplete="off" lay-verify="required" placeholder="请输入Aria2服务链接地址"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit=""  lay-filter="url_test">连接测试</button>
				</div>
			</div>

			<div class="layui-form-item layui-hide">
				<label class="layui-form-label">秘钥Token</label>
				<div class="layui-input-block">
					<input type="text" name="aria2_token" autocomplete="off" placeholder="(可选)请输入"
						class="layui-input">
				</div>
			</div>
		
			<div class="layui-form-item">
				<label class="layui-form-label">临时路径</label>
				<div class="layui-input-block">
					<input type="text" name="aria2_download_path" lay-verify="required" placeholder="请输入下载临时储存磁盘绝对路径" autocomplete="off"
						class="layui-input">
				</div>
			</div>
		
			
		
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-block">
					<select name="aria2_status" lay-filter="aihao">
						<option value="0" selected="">停用</option>
						<option value="1">启用</option>
					</select>
				</div>
			</div>
		
			<div></div>
		
			<div class="layui-form-item">
				<button class="layui-btn" id="save_user_info_btn" lay-submit="" lay-filter="save_config">保存</button>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	layui.use(['table','form'],function(){
		var table=layui.table,$=layui.$,form=layui.form;
		$("title").text('系统管理 - 私有云盘');

		// 获取初始值
		app.ajaxPost("/api/admin/aria2GetCfg",{},function(res){
			if(res.err_code==0){
				form.val("aria2_config",res.data)
			}
		})

		// 保存
		form.on('submit(save_config)', function (data) {
			// console.log(data.field)
			app.ajaxPost("/api/admin/aria2SetCfg", data.field, function (res) {
				if (res.err_code == 0) {
					layer.msg("保存成功")
				}
			})
			return false; //阻止表单跳转
		}); 

		// 连接测试
		form.on('submit(url_test)', function (data) {
			// console.log(data.field)
			app.ajaxPost("/api/admin/aria2TestUrl", data.field, function (res) {
				if (res.err_code == 0) {
					layer.msg("测试通过，当前Aria2版本：" + res.data.result.version)
				}else{
					layer.msg("连接失败，请检查地址是否正确")
				}
			})
			return false; //阻止表单跳转
		});
		form.render()
		app.runTpl('admin_menu', {elem: '#admin_menu'})
	})
</script>